package com.shallwead.bna.object;

import android.content.Context;
import android.provider.Settings;
import android.telephony.TelephonyManager;

public class GCM {

	public String id, udid, pkg;
	public Context mContext;

	public GCM(Context mContext, String id) {
		this.mContext = mContext;
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUdid() {
		return getUDID(mContext);
	}

	public void setUdid(String udid) {
		this.udid = udid;
	}

	public String getPkg() {
		return getPkgName(mContext);
	}

	public void setPkg(String pkg) {
		this.pkg = pkg;
	}

	public String getUDID(Context mContext) {
		TelephonyManager tm = ((TelephonyManager) mContext
				.getApplicationContext().getSystemService(
						Context.TELEPHONY_SERVICE));
		if (tm == null)
			return "NoTM_"
					+ Settings.Secure.getString(mContext
							.getApplicationContext().getContentResolver(),
							Settings.Secure.ANDROID_ID);
		else
			return ((tm.getDeviceId() != null) ? tm.getDeviceId() : "N")
					+ "_"
					+ ((tm.getSimSerialNumber() != null) ? tm
							.getSimSerialNumber() : "N")
					+ "_"
					+ Settings.Secure.getString(mContext
							.getApplicationContext().getContentResolver(),
							Settings.Secure.ANDROID_ID);
	}

	public String getPkgName(Context mContext) {
		String pkg = "";

		try {
			pkg = mContext.getApplicationContext().getPackageName();
		} catch (Exception e) {
		}

		return pkg;
	}

}
